# -*- coding: utf-8 -*-
"""
Created on Thu Apr 17 17:56:52 2025

@author: micha
"""

import pandas as pd
import sys
pd.options.plotting.backend = "plotly"
import plotly.io as pio
import plotly.graph_objects as go
pio.renderers.default='browser'
import numpy as np
from scipy import stats as st


sys.path.append(r"C:\Michael\Albany LAIO Lab and Research Projects\Python Utilities")

#send plots to current browser. Export from browser as .png
#pio.renderers.default='browser'

'''
Flags
'''
autoscale=True # autoscale flag. If true use autoscale on figures
save_images=True # If true save images to disk.

Image_dir = "C:/Michael/Albany LAIO Lab and Research Projects/Is a profile worth/images/"

Data_dir = "C:/Michael/Albany LAIO Lab and Research Projects/Is a profile worth/data/"



Cummulative_Data_DF = pd.read_csv("C:/Michael/Albany LAIO Lab and Research Projects/Is a profile worth/data/Cumulative monte carlo.csv")


Rows=[]

for variable in ['BACE','CC','DIS','IGB','PWR','SC','TASK','nACH-100','nAFF-100','nPWR-100','I1','P1']:

    print(variable)                                                                           

    Minimum = 1000
    while Minimum < 120000:              #40000:# Get data in a list
    
        print(Minimum)
        
        Temp_DF= Cummulative_Data_DF[(Cummulative_Data_DF['Words'] >= Minimum) & (Cummulative_Data_DF['Words'] < Minimum+1000)]
        
        '''Draws'''
        Draws= len(Temp_DF)
              
        Max_Distance=Temp_DF[variable].max()
        Min_Distance=Temp_DF[variable].min()                  
        CI95_Upper_Bound =Temp_DF[variable].quantile(0.975)
        CI95_Lower_Bound =Temp_DF[variable].quantile(0.025)
        CI84_Upper_Bound =Temp_DF[variable].quantile(0.92)
        CI84_Lower_Bound =Temp_DF[variable].quantile(0.08)
        
        Rows.append({'Variable': variable,
                     'Minimum': Minimum,
                     'Draws': Draws,
                     'Max_Distance': Max_Distance,
                     'Min_Distance': Min_Distance,
                     'CI95_Upper_Bound': CI95_Upper_Bound,
                     'CI95_Lower_Bound': CI95_Lower_Bound,
                     'CI84_Upper_Bound': CI84_Upper_Bound,
                     'CI84_Lower_Bound': CI84_Lower_Bound,
                     })
        
                    
        Minimum=Minimum+1000

Confidence_Intervals_DF=pd.DataFrame.from_records(Rows)

Confidence_Intervals_DF.to_excel(excel_writer=Data_dir+"Confidence Intervals.xlsx", index=False) 

